package com.mccken.practice.top100.Top_1$20.Top_15;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-01-02 22:15
 **/
public class FirstMissingPositive {

	// 数组转map用法
	public int firstMissingPositive(int[] nums) {
		int n = nums.length;
		for (int i = 0; i < n; i++) {
			if (nums[i] <= 0) {
				nums[i] = n+1;
			}
		}

		for (int i = 0; i < n; i++) {
			int num = Math.abs(nums[i]);
			if (num <= n) {
				nums[num-1] = -Math.abs(nums[num-1]);
			}
		}

		for (int i = 0; i < n; i++) {
			if (nums[i] > 0) {
				return i+1;	
			}
		}
		return n+1;
	}
}
